package com.hksj.vsm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hksj.common.config.annotation.CurrentUserIdAndName;
import com.hksj.common.config.utils.PageResult;
import com.hksj.common.core.model.Rest;
import com.hksj.vsm.dto.VideoDeviceDTO;
import com.hksj.vsm.dto.VideoDeviceStateDTO;
import com.hksj.vsm.entity.VideoDevice;
import com.hksj.vsm.query.VideoDeviceQuery;
import com.hksj.vsm.service.VideoDeviceManageService;
import com.hksj.vsm.vo.VideoDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "视频监控-视频设备管理")
@RestController
@RequestMapping("/api/videoDevice")
public class VideoDeviceManageController {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	public VideoDeviceManageService videoDeviceManageService;

	@PostMapping("/addVideoDevice")
	@CurrentUserIdAndName(id = "userId",name = "uname")
	@ApiOperation(value = "添加视频设备")
	public Rest<VideoDevice> addVideoDevice(@RequestBody VideoDeviceDTO dto){
		VideoDevice videoDevice = videoDeviceManageService.addVideoDevice(dto);
		return Rest.ok(videoDevice);
	}

	@GetMapping("/getVideoDevice/{id}")
	@ApiOperation(value = "获取视频设备信息")
	public Rest<VideoDeviceVO> getVideoDevice(@PathVariable String id){
		VideoDeviceVO videoDevice = videoDeviceManageService.getVideoDevice(id);
		return Rest.ok(videoDevice);
	}

	@CurrentUserIdAndName(id = "userId",name = "uname")
	@PostMapping("/updateVideoDevice")
	@ApiOperation(value = "修改视频设备")
	public Rest updateVideoDevice(@RequestBody VideoDeviceDTO dto){
		videoDeviceManageService.updateVideoDevice(dto);
		return Rest.ok();
	}

	@CurrentUserIdAndName(id = "userId",name = "uname")
	@PostMapping("/enableVideoDevice")
	@ApiOperation(value = "启用/禁用视频设备")
	public Rest enableVideoDevice(@RequestBody VideoDeviceStateDTO dto){
		videoDeviceManageService.enableVideoDevice(dto);
		return Rest.ok();
	}

	@DeleteMapping("/delVideoDevice/{id}")
	@ApiOperation(value = "删除视频设备")
	public Rest delVideoDevice(@PathVariable String id){
		videoDeviceManageService.delVideoDevice(id);
		return Rest.ok();
	}

	@PostMapping("/pageVideoDevice")
	@ApiOperation(value = "分页查询视频设备",response = VideoDeviceVO.class)
	public Rest<IPage<VideoDeviceVO>> pageVideoDevice(@RequestBody VideoDeviceQuery query){
    	IPage<VideoDeviceVO> page = videoDeviceManageService.pageVideoDevice(query);
		return Rest.ok(page);
	}

	@ApiOperation(value = "分页查询视频设备实体列表")
	@PostMapping("/queryVideoDeviceInstanceListByPaging")
	public Rest<PageResult<VideoDeviceVO>> queryVideoDeviceInstanceListByPaging(@RequestBody VideoDeviceQuery query){
		IPage<VideoDeviceVO> page = videoDeviceManageService.queryVideoDeviceInstanceListByPaging(query);

		//封装分页结果
		PageResult<VideoDeviceVO> result = PageResult.restPage(page);

		//返回结果
		return Rest.ok(result);
	}
}